﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PTExpress.Models.DatVe>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Đặt vé
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
        IEnumerable<SelectListItem> lsEXe = (IEnumerable<SelectListItem>)ViewData["lsEXe"];
        IEnumerable<SelectListItem> lsEChuyenXe = (IEnumerable<SelectListItem>)ViewData["lsEChuyenXe"];
        IEnumerable<SelectListItem> lsETuyenDuong = (IEnumerable<SelectListItem>)ViewData["lsETuyenDuong"];
        IEnumerable<SelectListItem> lsEKhachHang = (IEnumerable<SelectListItem>)ViewData["lsEKhachHang"];
        List<DTO.GheDTO> ls = (List<DTO.GheDTO>)ViewData["ds_ghe"];
        
    %>
    <h2>
        Đặt vé</h2>
    <% using (Html.BeginForm())
       { %>
    <%: Html.ValidationSummary(true, "Dữ liệu chưa được lưu trữ. Vui lòng sửa các lỗi bên dưới và nhấn Lưu.") %>
    <div>
        <fieldset>
            <legend>Thông tin vé</legend>
            <div class="editor-label">
                <%: Html.LabelFor(m => m.KhachHang) %>
            </div>
            <div class="editor-field">
                <%: Html.DropDownListFor(m => m.KhachHang, lsEKhachHang)%>
                <%: Html.ValidationMessageFor(m => m.KhachHang)%>
            </div>
            <div class="editor-label">
                <%: Html.LabelFor(m => m.ChuyenXe) %>
            </div>
            <div class="editor-field">
                <%: Html.DropDownListFor(m => m.ChuyenXe, lsEChuyenXe, new { onchange = "ChuyenXeSelected(this)" })%>
                <%: Html.ValidationMessageFor(m => m.ChuyenXe)%>
            </div>
            <div class="editor-label">
                <%: Html.LabelFor(m => m.SoGhe) %>
            </div>
            <div class="editor-field" id="chuyenxe">
                <%: Html.ValidationMessageFor(m => m.SoGhe)%>
            </div>
            <p>
                <input type="submit" value="Lưu" />
            </p>
        </fieldset>
    </div>
    <% } %>
    
    <script>
        var chuyenXeSelected = null;
        function GenerationDIV(t) {
            var chuyenxe = document.getElementById("chuyenxe");
            var div = document.getElementById("chuyenXe_" + t.chuyenXe);
            if (div == null ) {
                div = document.createElement("div");
                div.id = "chuyenXe_" + t.chuyenXe;
                div.style.width = "240px";
                div.style.display = "none";
                chuyenxe.appendChild(div);
            }
            var ghe = document.createElement("div");
            ghe.style.cssFloat = "left";
            ghe.style.width = "60px";
            ghe.innerHTML = "<label>&nbsp&nbsp<input id='"+t.chuyenXe+"_"+ t.masSoghe +"' name='SoGhe' type='radio' value='"+ t.masSoghe+"' />" + t.masSoghe + "&nbsp&nbsp</label>";
            div.appendChild(ghe);
            if (t.khachHang!=0) {
                var r = document.getElementById(t.chuyenXe+"_"+ t.masSoghe);
                r.disabled = "disabled";
            }
        }
        function GenerationHTML(a) {
            for(i=0; i<a.length;i++) {
                GenerationDIV(a[i]);
            }
            var chuyenxe = document.getElementById("chuyenxe");
            var clear = document.createElement("div");
            clear.className = "clear";
            chuyenxe.appendChild(clear);
        }
        function ChuyenXeSelected(ghe) {
            if (chuyenXeSelected != null) {
                chuyenXeSelected.style.display = "none";
                $("#" + chuyenXeSelected.id + " input").attr('checked', false);
            }
            if (ghe.value) {
                var n = document.getElementById("chuyenXe_"+ghe.value);
                n.style.display = "block";
                chuyenXeSelected = n;
            } else {
                chuyenXeSelected = null;
            }
        }
        var viTriGhe = [
        <% for (int i = 0; i < ls.Count; i++){ %>
        { chuyenXe: <%= ls[i].ChuyenXeId  %> , masSoghe:<%= ls[i].MaSoGhe %>, khachHang: <%=ls[i].KhachHangId%>}
            <% if ( i < ls.Count - 1) Response.Write(","); %>
        <% } %>
        ];

        GenerationHTML(viTriGhe);
        
    </script>
</asp:Content>
